﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Safe_Driving.TokenUser;
using Safe_Driving.EasyCalendar.Model;

namespace Safe_Driving.EasyCalendar.Controler
{
    /// <summary>
    /// 
    ///     <MyNamespace:EventCalendar/>
    ///
    /// </summary>
    public class EventCalendar : ContentControl
    {
        static EventCalendar()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(EventCalendar), new FrameworkPropertyMetadata(typeof(EventCalendar)));
            CommandManager.RegisterClassCommandBinding(typeof(EventCalendar), new CommandBinding(Reserver, new ExecutedRoutedEventHandler(OnExecutedReserver), new CanExecuteRoutedEventHandler(OnCanExecuteReserver)));
        }


        #region btn Reserver

        public static readonly RoutedCommand Reserver = new RoutedCommand("Reserver", typeof(EventCalendar));

        private static void OnCanExecuteReserver(object sender, CanExecuteRoutedEventArgs e)
        {
            ((EventCalendar)sender).OnCanExecuteReserver(e);
        }


        private static void OnExecutedReserver(object sender, ExecutedRoutedEventArgs e)
        {
            SingletonTokenUser tok = SingletonTokenUser.GetInstance();

            //création de cours
            if (tok.Current_tab == "cours_test")
            {
                tok.Mw.delete_cours(((EventCal)((EventCalendar)sender).Content).Id);
            }
            //Réservation de cours
            else if (tok.Current_tab == "Reservation_formation_TabItem")
            {
                tok.Mw.manage_reservation((EventCalendar)sender);
            }
            //Création d'indispos
            else if (tok.Current_tab == "indispo_Moniteur_TabItem")
            {
                tok.Mw.delete_indispo(((EventCal)((EventCalendar)sender).Content).Id);
            }
            

            e.Handled = true;
        }

        protected virtual void OnCanExecuteReserver(CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
            e.Handled = false;
        }

        #endregion

        #region StartTime

        public static readonly DependencyProperty StartTimeProperty =
                DependencyProperty.RegisterAttached("StartTime", typeof(DateTime), typeof(EventCalendar),
                    new FrameworkPropertyMetadata((DateTime)DateTime.Now));

            public DateTime StartTime
            {
                get { return (DateTime)GetValue(StartTimeProperty); }
                set { SetValue(StartTimeProperty, value); }
            }


        #endregion


        #region EndTime

            public static readonly DependencyProperty EndTimeProperty =
           DependencyProperty.RegisterAttached("EndTime", typeof(DateTime), typeof(EventCalendar),
               new FrameworkPropertyMetadata((DateTime)DateTime.Now));

         
            public DateTime EndTime
            {
                get { return (DateTime)GetValue(EndTimeProperty); }
                set { SetValue(EndTimeProperty, value); }
            }

        #endregion


    }
}
